import math

def is_prime(a):
    for b in range(2, int(math.sqrt(a)) + 1):
        if a % b == 0:
            return False
    return True

def split(string, delimiter):
    return string.split(delimiter)

digits = {
    "zero": 0,
    "one": 1,
    "two": 2,
    "three": 3,
    "four": 4,
    "five": 5,
    "six": 6,
    "seven": 7,
    "eight": 8,
    "nine": 9
}

input_str = input()
result = ""

for word in split(input_str, ' '):
    if word in digits:
        result += str(digits[word])
    else:
        print("Wrong input")
        exit(1)

r_int = int(result)

j = next(l for l in range(r_int, r_int * 1000) if is_prime(l))
k = next(z for z in range(r_int, 1, -1) if is_prime(z))

if r_int - k > j - r_int:
    print(j)
else:
    print(k)

